package cn.sytton.taffecloud.service.log.controller;

import cn.sytton.taffecloud.common.base.doc.Api;
import cn.sytton.taffecloud.common.base.doc.ApiImplicitParam;
import cn.sytton.taffecloud.common.base.doc.ApiOperation;
import cn.sytton.taffecloud.common.base.doc.ParamType;
import cn.sytton.taffecloud.common.db.model.PageParam;
import cn.sytton.taffecloud.service.log.constants.AccessSource;
import cn.sytton.taffecloud.service.log.entity.UserLogEntity;
import cn.sytton.taffecloud.service.log.service.IUserLogService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户操作日志控制层
 *
 * @author skyrock
 */
@Api(tags = "用户操作日志")
@RestController
@RequestMapping("/user")
public class UserLogController {

    @Resource
    private IUserLogService userLogService;

    @ApiOperation(value = "添加用户操作日志")
    @ApiImplicitParam(name = "entity", value = "用户操作日志对象", paramType = ParamType.body, dataTypeClass = UserLogEntity.class)
    @PostMapping("/pc")
    public void create(@RequestBody UserLogEntity entity) {
        entity.setAccessSource(AccessSource.pc.name());
        userLogService.create(entity);
    }

    @ApiOperation("查询分页访问日志列表")
    @ApiImplicitParam(name = "pp", value = "分页参数对象", paramType = ParamType.query, dataTypeClass = PageParam.class)
    @GetMapping
    public PageInfo<UserLogEntity> findListPage(PageParam pp) {
        return userLogService.findListPage(pp);
    }

}
